#-*-coding:utf-8-*-

import requests
import time
import os
import json
openid = 'o5O7ossr7McXTsZqkdYMUlramPLk'
header_one = {'Host': 'cxj4.wxfcgfj.cn',
              'User-Agent': 'Mozilla/5.0 (Linux; Android 6.0; 1503-M02 Build/MRA58K) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/37.0.0.0 Mobile MQQBrowser/6.2 TBS/036558 Safari/537.36 MicroMessenger/6.3.25.861 NetType/WIFI Language/zh_CN',
              'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
              'Accept-Language': 'zh-CN,zh;q=0.8,en-US;q=0.5,en;q=0.3',
              'Accept-Encoding': 'gzip, deflate',
              'Referer': r'http://api4.jutingshop.com/html5/get-weixin-code.html?appid=wxf70115ca9fe6b2ef&redirect_uri=http%3a%2f%2fcxj4.wxfcgfj.cn%2fmembers%2fvote_detail.aspx%3fid%3d3050%26pid%3d326742&scope=snsapi_base&state=123&code=021Pj4KQ13vyP61YuCGQ1zrVJQ1Pj4Kt&state=123',
              'Connection': 'keep-alive',
              'Set-Cookie': 'wx_openid=JT='+ openid +'; expires=Tue, 12-Sep-2017 14:33:47 GMT; path=/',
              'Upgrade-Insecure-Requests': '1',
              'Cache-Control': 'max-age=0'
              }
header_two = {'Host': 'cxj4.wxfcgfj.cn',
              'User-Agent': 'Mozilla/5.0 (Linux; Android 6.0; 1503-M02 Build/MRA58K) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/37.0.0.0 Mobile MQQBrowser/6.2 TBS/036558 Safari/537.36 MicroMessenger/6.3.25.861 NetType/WIFI Language/zh_CN',
              'Accept': 'application/json, text/javascript, */*;q = 0.01',
              'Accept-Language': 'zh-CN,zh;q=0.8,en-US;q=0.5,en;q=0.3',
              'Accept-Encoding': 'gzip, deflate',
              'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8',
              'X-Requested-With': 'XMLHttpRequest',
              'Connection': 'keep-alive',
              'Referer': r'http://cxj4.wxfcgfj.cn/members/vote_detail.aspx?id=3050&pid=326742&code=0112O8U31snC5P1mCtR31uS5U312O8Ul',
              'Content-Length': '77'

              }
data = {'action': 'ticket',
        'formhash': openid,
        'id': '326742',
        'qiyihash': 'aaaaa2'     
        }

cookie = {}  # dict(response_one.cookies)
cookie['wx_openid'] = 'JT='+openid
with requests.Session() as s:
    s.get('http://cxj4.wxfcgfj.cn/members/vote_detail.aspx?id=3050&pid=326742&code=07147mcc1rIA8s07WMdc1sVbcc147mci', headers=header_one)
    response_one = s.get(
        'http://cxj4.wxfcgfj.cn/members/vote_detail.aspx?id=3050&pid=326742&code=021Pj4KQ13vyP61YuCGQ1zrVJQ1Pj4Kt, headers=header_one')
    # cookie = {}   dict(response_one.cookies)
    # cookie['wx_openid'] = 'JT=o5O7ossr7McXTsZqkdYMUlramPLk'

    response_two = s.post('http://cxj4.wxfcgfj.cn/tools/json_ajax.ashx?index_id=3050&user_id=5827',
                          headers=header_two, data=data, cookies=cookie)
    response_two.encoding = 'utf-8'
    # print(response_two.cookies)

# print(dict(response_one.cookies))
print(json.loads(response_two.text))
print(response_two.request.headers)
